package com.tao.mytestgreendao;

import com.tao.utils.TimeSimpleUtil;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;

import java.text.ParseException;

import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Property;

/**
 * UserBean实体类，存储数据库中user表中的数据
 * <p>
 * 注解：
 * DatabaseTable：通过其中的tableName属性指定数据库名称
 * DatabaseField：代表数据表中的一个字段
 * ForeignCollectionField：一对多关联，表示一个UserBean关联着多个ArticleBean（必须使用ForeignCollection集合）
 * <p>
 * 属性：
 * id：当前字段是不是id字段（一个实体类中只能设置一个id字段）
 * columnName：表示当前属性在表中代表哪个字段
 * generatedId：设置属性值在数据表中的数据是否自增
 * useGetSet：是否使用Getter/Setter方法来访问这个字段
 * canBeNull：字段是否可以为空，默认值是true
 * unique：是否唯一
 * defaultValue：设置这个字段的默认值
 */

// 历史记录
@Entity(nameInDb = "fundsinfo")
public class FundsinfoBean {

    // 日期 ，开盘价，最高价，最低价，收盘价，权重 ，成交量

    @Id(autoincrement = true)
    @Property(nameInDb = "id")
    Long id;
    @Property(nameInDb = "Date")
    String Date;
    @Property(nameInDb = "Open")

    String Open;
    @Property(nameInDb = "High")
    String High;
    @Property(nameInDb = "Low")
    String Low;
    @Property(nameInDb = "Close")
    String Close;
    @Property(nameInDb = "Adj_Close")
    String Adj_Close;
    @Property(nameInDb = "Volume")
    String Volume;
    @Property(nameInDb = "Code")
    String Code;
    /**
     * 均价
     */
    @Property(nameInDb = "averagePrice")
    String averagePrice;
    @Property(nameInDb = "conceal")

    Boolean conceal = false;
    @Property(nameInDb = "timeStemp")

    long timeStemp;

    /**
     * 是否无需更新
     */
    @Property(nameInDb = "aUpdate")

    Boolean aUpdate = false;

    public FundsinfoBean() {
    }

    public FundsinfoBean(String code, String date, String open, String high, String low, String close, String adj_Close, String volume) {
        this.Date = date;
        this.Open = open;
        this.High = high;
        this.Low = low;
        this.Close = close;
        this.Adj_Close = adj_Close;
        this.Volume = volume;
        this.Code = code;
        average();
        try {
            setTimeStemp(TimeSimpleUtil.parse("yyyy-MM-dd", date).getTime());
        } catch (ParseException e) {
//            e.printStackTrace();
            try {
                setTimeStemp(TimeSimpleUtil.parse("yyyy/MM/dd", date).getTime());

            } catch (ParseException ex) {
                ex.printStackTrace();
            }

        }
    }

    @Generated(hash = 69056167)
    public FundsinfoBean(Long id, String Date, String Open, String High, String Low, String Close, String Adj_Close, String Volume, String Code,
                         String averagePrice, Boolean conceal, long timeStemp, Boolean aUpdate) {
        this.id = id;
        this.Date = Date;
        this.Open = Open;
        this.High = High;
        this.Low = Low;
        this.Close = Close;
        this.Adj_Close = Adj_Close;
        this.Volume = Volume;
        this.Code = Code;
        this.averagePrice = averagePrice;
        this.conceal = conceal;
        this.timeStemp = timeStemp;
        this.aUpdate = aUpdate;
    }

    public Boolean getaUpdate() {
        return aUpdate;
    }

    public void setaUpdate(Boolean aUpdate) {
        this.aUpdate = aUpdate;
    }

    private void average() {
        try {
            float f = Float.parseFloat(Open);
            f += Float.parseFloat(Close);
            f += Float.parseFloat(High);
            f += Float.parseFloat(Low);
            averagePrice = f / 4 + "";
        } catch (Throwable e) {
//                e.printStackTrace();
        }
    }

    public boolean isaUpdate() {
        return aUpdate;
    }

    public void setaUpdate(boolean aUpdate) {
        this.aUpdate = aUpdate;
    }

    public long getTimeStemp() {
        return timeStemp;
    }

    public void setTimeStemp(long timeStemp) {
        this.timeStemp = timeStemp;
    }

    public boolean isConceal() {
        return conceal;
    }

    public void setConceal(boolean conceal) {
        this.conceal = conceal;
    }

    public String getAveragePrice() {
        return averagePrice;
    }

    public void setAveragePrice(String averagePrice) {
        this.averagePrice = averagePrice;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCode() {
        return Code;
    }

    public void setCode(String code) {
        Code = code;
    }

    public String getDate() {
        return Date;
    }

    public void setDate(String date) {
        Date = date;
        try {
            timeStemp = TimeSimpleUtil.parse("yyyy-MM-dd", date).getTime();
        } catch (Exception e) {
//            e.printStackTrace();
//            System.err.println( "1:"+date);
            try {
                timeStemp = TimeSimpleUtil.parse("yyyy/MM/dd", date).getTime();
            } catch (Exception e1) {
//                e1.printStackTrace();
//                System.err.println("2:"+date);

            }
        }
    }

    public String getOpen() {
        return Open;
    }

    public void setOpen(String open) {
        Open = open;
    }

    public String getHigh() {
        return High;
    }

    public void setHigh(String high) {
        High = high;
    }

    public String getLow() {
        return Low;
    }

    public void setLow(String low) {
        Low = low;
    }

    public String getClose() {
        return Close;
    }

    public void setClose(String close) {
        Close = close;
    }

    public String getAdj_Close() {
        return Adj_Close;
    }

    public void setAdj_Close(String adj_Close) {
        Adj_Close = adj_Close;
    }

    public String getVolume() {
        return Volume;
    }

    public void setVolume(String volume) {
        Volume = volume;
    }

    @Override
    public String toString() {
        return "FundsinfoBean{" +
                "id=" + id +
                ", Date='" + Date + '\'' +
                ", Open='" + Open + '\'' +
                ", High='" + High + '\'' +
                ", Low='" + Low + '\'' +
                ", Close='" + Close + '\'' +
                ", Adj_Close='" + Adj_Close + '\'' +
                ", Volume='" + Volume + '\'' +
                ", Code='" + Code + '\'' +
                ", averagePrice='" + averagePrice + '\'' +
                '}';
    }

    public Boolean getConceal() {
        return this.conceal;
    }

    public void setConceal(Boolean conceal) {
        this.conceal = conceal;
    }

    public Boolean getAUpdate() {
        return this.aUpdate;
    }

    public void setAUpdate(Boolean aUpdate) {
        this.aUpdate = aUpdate;
    }
}
